package com.changhongit.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.changhongit.dao.OrderDao;
import com.changhongit.entity.Order;
import com.changhongit.returnentity.ReturnOrder;
import com.changhongit.returnentity.ServiceOrderNum;
import com.changhongit.returnentity.ServiceOrderNumMonth;
import com.changhongit.returnentity.ServiceOrderNumYear;
import com.changhongit.service.OrderService;
import com.changhongit.util.PageView;

@Transactional
@Service("orderService")
public class OrderServiceImpl implements OrderService {
	@Autowired
	private OrderDao orderDao;

	@Override
	public void add(Order order) {
		orderDao.addOrder(order);
	}

	@Override
	public PageView query(PageView pageView, ReturnOrder returnOrder) {
		List<ReturnOrder> list = orderDao.query(pageView, returnOrder);
		pageView.setRecords(list);
		return pageView;
	}

	@Override
	public Order getById(String id) {
		Order order = orderDao.getById(id);
		return order;
	}

	@Override
	public void modify(Order order) {
		orderDao.modify(order);
	}

	@Override
	public int findCountOrder() {
		return orderDao.findCountOrder();
	}

	@Override
	public PageView queryServiceOrderNum(PageView pageView,ReturnOrder returnOrder) {
		List<ServiceOrderNum> list = orderDao.queryServiceOrderNum(pageView,returnOrder);
		pageView.setRecords(list);
		return pageView;
	}

	@Override
	public PageView queryServiceOrderNumYear(PageView pageView,ReturnOrder order) {
		List<ServiceOrderNumYear> list = orderDao.queryServiceOrderNumYear(pageView,order);
		pageView.setRecords(list);
		return pageView;
	}

	@Override
	public PageView queryRevenueByYear(PageView pageView,ReturnOrder order) {
		List<ServiceOrderNumYear> list = orderDao.queryRevenueByYear(pageView,order);
		pageView.setRecords(list);
		return pageView;
	}

	@Override
	public PageView queryServiceUserRevenueByYear(PageView pageView,
			ReturnOrder order) {
		List<ServiceOrderNumYear> list = orderDao.queryServiceUserRevenueByYear(pageView, order);
		pageView.setRecords(list);
		return pageView;
	}

	@Override
	public int queryUnReadOrder(ReturnOrder returnOrder) {
		return orderDao.queryUnReadOrder(returnOrder);
	}

	@Override
	public PageView queryServiceOrderNumMonth(PageView pageView,
			ReturnOrder order) {
		if("B".equals(order.getOrderStatus())){
			List<ServiceOrderNumYear> list = orderDao.queryServiceOrderNumMonth(pageView, order);
			pageView.setRecords(list);
		}else if("C".equals(order.getOrderStatus())){
			List<ServiceOrderNumYear> list = orderDao.queryServiceOrderNumDay(pageView, order);
			pageView.setRecords(list);
		}
		return pageView;
	}

	@Override
	public PageView queryServiceOrderNumYMonth(PageView pageView,
			ReturnOrder order) {
		List<ServiceOrderNumMonth> list = orderDao.queryServiceOrderNumYMonth(pageView, order);
		pageView.setRecords(list);
		return pageView;
	}

	@Override
	public PageView queryServiceUserRevenueByMonth(PageView pageView,
			ReturnOrder order) {
		if("B".equals(order.getOrderStatus())){
			List<ServiceOrderNumYear> list = orderDao.queryServiceUserRevenueByMonth(pageView, order);
			pageView.setRecords(list);
		}else if("C".equals(order.getOrderStatus())){
			List<ServiceOrderNumYear> list = orderDao.queryServiceUserRevenueByDay(pageView, order);
			pageView.setRecords(list);
		}
		return pageView;
	}

	@Override
	public PageView queryServiceUserRevenueByYMonth(PageView pageView,
			ReturnOrder order) {
		List<ServiceOrderNumMonth> list = orderDao.queryServiceUserRevenueByYMonth(pageView, order);
		pageView.setRecords(list);
		return pageView;
	}

	@Override
	public PageView queryRevenueByMonth(PageView pageView, ReturnOrder order) {
		if("B".equals(order.getOrderStatus())){
			List<ServiceOrderNumYear> list = orderDao.queryRevenueByMonth(pageView, order);
			pageView.setRecords(list);
		}else if("C".equals(order.getOrderStatus())){
			List<ServiceOrderNumYear> list = orderDao.queryRevenueByDay(pageView, order);
			pageView.setRecords(list);
		}
		return pageView;
	}

	@Override
	public PageView queryRevenueByYmonth(PageView pageView, ReturnOrder order) {
		List<ServiceOrderNumMonth> list = orderDao.queryRevenueByYmonth(pageView, order);
		pageView.setRecords(list);
		return pageView;
	}
}
